// 权限控制
import router from "@/router";
import store from "@/store";
const WHITE_LIST = ["/login", "/404"]; // 白名单
router.beforeEach((to, from, next) => {
  // to:去往的路由对象
  // from：从哪里来的那个路由对象
  // next:放行函数
  //   获取token
  const token = store.state.user.token;
  if (token) {
    // 有token
    console.log(token);
    if (to.path === "/login") {
      next("/");
    } else {
      next();
    }
  } else {
    // 没有token
    if (WHITE_LIST.includes(to.path)) {
      next();
    } else {
      next("/login");
    }
  }
});
